import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//引入axios 
import axios from 'axios'
//导入echarts数据库可视化 
import * as echarts from 'echarts';
//将echarts挂载至Vue属性中，属性名$echarts 
Vue.prototype.$echarts = echarts;
//axios域名配置，即服务端API服务器域名， 
axios.defaults.baseURL = 'http://127.0.0.1:4000'
//把axios挂载至Vue全局属性中 
Vue.prototype.$http = axios

//引入element-ui 
import elementui from 'element-ui'
//引入index.css样式 
import 'element-ui/lib/theme-chalk/index.css'
//vue中注册使用element-ui 
Vue.use(elementui)

Vue.config.productionTip = false
//前置路由守卫，判断路由权限 
//前置路由守卫，判断路由权限 
router.beforeEach((to, from, next) => {
  //判断是否访问Login页面 
  if (to.path === '/Login') { return next() }
  //判断缓存中是否存在登录信息 
  let admin = localStorage.getItem('admin')
  if (!admin) { return next('/Login') }
  //判断页面权限 
  const { role } = to.meta
  if (role) {
    admin = JSON.parse(admin)
    if (admin.role != role) { alert('您无权访问') } else { next() }
  } else { next() }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
